﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using HYBYSoft.Company.Models;

namespace HYBYSoft.Company.WebSite.Controllers
{
    public class ProductController : Controller
    {
        /// <summary>
        /// 数据库实体上下文对象
        /// </summary>
        CompanySiteEntities _dbContext = new CompanySiteEntities();

        /// <summary>
        /// 产品展示列表页面Get请求
        /// </summary>
        /// <param name="id">类别编号</param>
        /// <returns></returns>
        public ActionResult Index(int id)
        {
            var products = from p in _dbContext.Articles
                           join c in _dbContext.Categories on p.CategoryID equals c.CategoryID
                           where p.CategoryID == id && p.IsRelease == 1
                           orderby p.CreateTime descending
                           select p;

            return View(products);
        }

        /// <summary>
        /// 产品查看页面Get请求
        /// </summary>
        /// <param name="id">文章编号</param>
        /// <returns></returns>
        public ActionResult Details(int id)
        {
            var product = _dbContext.Articles.FirstOrDefault(a => a.ArticleID == id && a.IsRelease == 1);

            return View(product);
        }
    }
}
